package devmento.gae.resources;


import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import devmento.gae.dao.UserDaoJdo;
import devmento.gae.model.User;

@Path("/users")
@Component
public class UserResource {
        final Logger logger = LoggerFactory.getLogger(UserResource.class);
        
        @Autowired
        private UserDaoJdo userDao;
        
        @GET
        @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public User test(){
        	User user = new User("hong", "hong gildong", 24, "gdhong@gmail.com");
        	return user;
        }
        @GET
        @Path("/{id}")
        @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public User getUser(@PathParam("id")String id){
        	return userDao.find(id);
        }
        
        @DELETE
        @Path("/{id}")
        public void deleteUser(@PathParam("id")String id){
        	userDao.delete(id);
        }
        
        @POST
        @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public void createUser(User user){
        	userDao.create(user);
        }
        
        @PUT
        @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        public void updateUser(User user){
        	userDao.update(user);
        }
}

